<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	
	if (isset($_GET['building_id']))
	{
		$building_id = mysql_real_escape_string(strip_tags($_GET['building_id']));
	}
	
	if (isset($_GET['order']))
	{
		$order = mysql_real_escape_string(strip_tags($_GET['order']));
	}
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');

?>

	
	<table class="postSchedule">
        <tr>
        	<th colspan="2"></th>
        	<th><a href="postSchedule.php?order=course&building_id=<?php echo $building_id; ?>">Course/Section</a></th>
           	<th><a href="postSchedule.php?order=inst&building_id=<?php echo $building_id; ?>">Instructor</a></th>
            <!--
			<th><a href="postSchedule.php?order=room&building_id=<?php echo $building_id; ?>">Room</a></th>
            <th><a href="postSchedule.php?order=day&building_id=<?php echo $building_id; ?>">Days</a></th>
            <th><a href="postSchedule.php?order=time&building_id=<?php echo $building_id; ?>">Time</a></th>
			-->
	   </tr>

	
		
	<?php
	/*$query = "SELECT *, b.abbreviation AS b_abbrev, csub.abbreviation AS sub_abbrev, cs.id AS course_section_id, s.id AS schedule_id
			  FROM schedule s
			  JOIN course_sections cs ON cs.id = s.course_section_id
			  JOIN course_section_mapping csm ON csm.course_section_id = cs.id
			  JOIN courses c on c.id = csm.course_id
			  JOIN course_subjects csub ON csub.id = c.course_subject_id
			  JOIN instructors i ON i.id = cs.instructor_id
			  JOIN classrooms cr ON cr.id = s.classroom_id
			  JOIN buildings b ON b.id = cr.building_id
			  JOIN time_slots ts ON ts.id = s.time_slot_id
			  WHERE semester_id = '1'
			  AND cr.building_id = '$building_id'
			  GROUP BY cs.id ";
		*/
		
		$query = 
			   "SELECT *
				FROM course_sections cs
				JOIN instructors i ON i.id = cs.instructor_id
				JOIN course_section_mapping csm ON csm.course_section_id = cs.id
				JOIN courses c ON c.id = csm.course_id
				JOIN course_subjects csub ON csub.id = c.course_subject_id
				WHERE cs.id
				NOT IN
				(
				SELECT course_section_id
				FROM schedule s
				)";
				
		$result = mysql_query($query);
		//echo mysql_error();
		
		while ($row = mysql_fetch_assoc($result)) {
			//print_r($row);
			/*
			print $row['id'] . "<br/>";
			print $row['section_number'] . "\n";
			print $row['semester_id'];
			print $row['instructor_id'];
			print $row['classroom_type_id'];
			print $row['num_seats'];
			print $row['honors_program'];
			$id = $row['id'];
			$section_number = $row['section_number'];
			$semester_id = $row['semester_id'];
			$instructor_id = $row['instructor_id'];
			$classroom_type_id = $row['classroom_type_id'];
			$num_seats = $row['num_seats'];
			$honors_program = $row['honors_program'];
			*/
						
			$instructor = $row['last_name'];
			$course_number = $row['course_number'];
			$abbr = $row['abbreviation'];
			$sem_id = $row['semester_id'];
		
			
		
			//echo "<h1>$c</h1>";
		?>
		
		<tr>

		<td><a href="editSchedule.php">Schedule</a></td>
		
		<td><a href="collision_log.php">Collision Log</a></td>
		<td>
		<?php 
		
		if (strlen($sem_id == 1)) {$sem_id = "00".$sem_id;}
		else if ($sem_id == 2) 
			{$sem_id = "0".$sem_id;}
		
		
		echo "$abbr $course_number - $sem_id"; ?>
		
		</td>
		<td><?php echo $instructor; ?></td>
		
		</tr>
		
		<?php
		
			
	
		}
		
		?>
    </table>

	

	
<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>